package com.hit.aircraftwar.service;

import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Binder;
import android.os.IBinder;

import com.hit.aircraftwar.R;

import java.util.HashMap;

public class MusicService extends Service {

    private final HashMap<Integer, Integer> soundID = new HashMap<>();
    private SoundPool mSoundPool;

    public MusicService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mSoundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 5);
        soundID.put(1, mSoundPool.load(this, R.raw.bullet_hit, 1));
        soundID.put(2, mSoundPool.load(this, R.raw.bullet, 1));
        soundID.put(3, mSoundPool.load(this, R.raw.get_supply, 1));
        soundID.put(4, mSoundPool.load(this, R.raw.bomb_explosion, 1));
        soundID.put(5, mSoundPool.load(this, R.raw.game_over, 1));
    }

    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder();
    }

    public class MyBinder extends Binder {

        public void playMusic(int id){
            mSoundPool.play(soundID.get(id), 1, 1, 0,0,1);
        }
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
